package com.wuhongyu.controller;

import javax.servlet.http.HttpSession;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wuhongyu.entity.Admin;
import com.wuhongyu.service.impl.AdminServiceImpl;

@Controller
public class LoginController {

	
	@Autowired
	private AdminServiceImpl adminServiceImpl;
	
	@RequestMapping("/login")
	public String login() {
		return "login";
	}
	
	@RequestMapping("/tologin")
	public String adminLogin(HttpSession session,@Param("Admin")Admin admin) {
		if(adminServiceImpl.login(admin)) {
			session.setAttribute("admin", admin);
			return "admin/main";
		}else {
			return "msg";
		}
	}
	
	@RequestMapping("/logout")
	public String logout(HttpSession session) {
		session.invalidate();
		return "main";
	}
}
